package com.rbac.web.model;

import java.util.ArrayList;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

/**
 * @author gengaoliu
 */
@Data
@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class Permission extends BaseModel {

  private String code;
  private String name;
  private String value;
  private PermissionType type;
  private Integer menuId;
  private String remark;
  private PermissionAction action;
  private String path;
  private Integer pId;
  private Integer sort;
  private String displayName;
  private String icon;
  private List<Integer> pIds;
  private List<Integer> menuIds;

  public PermissionTree toPermissionTree() {
    PermissionTree permissionTree =
        PermissionTree.builder()
            .id(getId())
            .code(code)
            .name(name)
            .value(value)
            .type(type)
            .menuId(menuId)
            .pId(pId)
            .remark(remark)
            .action(action)
            .sort(sort)
            .displayName(displayName)
            .icon(icon)
            .path(path)
            .children(new ArrayList<>())
            .pIds(pIds)
            .menuIds(menuIds)
            .build();
    permissionTree.setMata(code, icon, sort);
    return permissionTree;
  }
}
